<?php
//var_dump($payment_mode);
$tuit_total = 0.00;
$matr_total = 0.00;
$misc_total = 0.00;
$othe_total = 0.00;
?>

<link rel="stylesheet" href="<?=style_url('yahoocssreset');?>">
<link rel="stylesheet" href="<?=style_url('formletter');?>">

<style type="text/css">
   table { page-break-inside:auto; }
   tr    { page-break-inside:avoid; page-break-after:auto }
</style>

<table><tr><td>&nbsp;</td></tr></table>

<table cellSpacing="0" cellPadding="0" style="width:818px;">
	<tr>
		<td style="width:200px; vertical-align:top; text-align:right;"><img src="<?php echo image_url("westfieldslogo.jpg"); ?>" alt="westfields logo" height="80px" /></td>
		<td style="width:418px; vertical-align:top; text-align:center;">
			<table cellSpacing="0" cellPadding="0" style="text-align:center;">
				<tr><td>&nbsp;</td></tr>
				<tr><td style="font-size:16px;">WESTFIELDS INTERNATIONAL SCHOOL</td></tr>
				<tr><td style="font-size:12px">School Year <?php echo $schoolyear_date; ?></td></tr>
				<tr><td style="font-size:12px;"><?=$school_address;?></td></tr>
				<tr><td style="font-size:12px;">Telephone Nos.: (045) 887-4966; (045) 322-2862</td></tr>
				<tr><td style="font-size:12px;">Mobile Numbers: 0917-520-0001; 0917-510-0002</td></tr>
				<tr><td style="font-size:12px;">www.westfields-is.com; <?=$school_email;?></td></tr>
			</table>
		</td>
		<td style="width:200px; vertical-align:top;">&nbsp;</td>
	</tr>
</table>

<table cellspacing="0" cellpadding="4" style="width:818px;">
	<tr><td style="width:50px;">&nbsp;</td><td width="718px">&nbsp;</td><td style="width:50px;">&nbsp;</td></tr>
	<tr><td>&nbsp;</td><td>
		<table cellspacing="0" cellpadding="4" style="border:#000 1px solid; width:318px;">
			<tr><td style="padding: 4px; border-bottom:#000 1px solid;">Invoice To</td></tr>
			<tr><td style="padding: 4px;"><?php echo ucwords(strtolower($student->firstname));?> <?php echo $student->middlename!='' ? ucwords(strtolower($student->middlename)).' ':'';?><?php echo ucwords(strtolower($student->lastname));?> <?php echo ucwords(strtolower($student->name_ext));?></td></tr>
			<tr><td style="padding: 4px;"><?php echo $student->level_code;?> SY <?php echo $schoolyear_date; ?></td></tr>
		</table>
	</td><td>&nbsp;</td></tr>
	<tr><td colspan="3">&nbsp;</td></tr>
	<tr><td>&nbsp;</td><td>
		<table cellspacing="0" cellpadding="4" style="width:718px;">
			<tr>
				<td style="padding:4px; width:318px;">&nbsp;</td>
				<td style="padding:4px; width:100px;">&nbsp;</td>
				<td style="padding:4px; width:150px;">&nbsp;</td>
				<td style="padding:4px; border:#000 1px solid; text-align:center; width:150px;">Terms</td>
			</tr>
			<tr>
				<td style="padding:4px; width:318px;">&nbsp;</td>
				<td style="padding:4px; width:100px;">&nbsp;</td>
				<td style="padding:4px; width:150px;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; border-left:#000 1px solid; text-align:center; width:150px;"><?php echo ucwords(strtolower($payment_mode->payment_mode)); ?></td>
			</tr>
		</table>
	</td><td>&nbsp;</td></tr>
	<tr><td>&nbsp;</td><td>
		<table cellspacing="0" cellpadding="4" style="border:#000 1px solid; width:718px;">
			<tr>
				<td style="padding:4px; border-bottom:#000 1px solid; border-right:#000 1px solid; text-align:center; width:318px;">Description</td>
				<td style="padding:4px; border-bottom:#000 1px solid; border-right:#000 1px solid; text-align:center; width:100px;">Qty</td>
				<td style="padding:4px; border-bottom:#000 1px solid; border-right:#000 1px solid; text-align:center; width:150px;">Rate</td>
				<td style="padding:4px; border-bottom:#000 1px solid; text-align:center; width:150px;">Amount</td>
			</tr>
			<?if(!empty($tuit_fees)):?>
			<?foreach($tuit_fees as $key => $value):?>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;"><?=$value->sef_fee_name;?></td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
				<td style="padding:4px; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
			</tr>
			<?php
			$tuit_total = $tuit_total + $value->sef_fee_rate;
			?>
			<?endforeach;?>
			<?endif;?>
			<?if(!empty($cca_fees)):?>
			<?foreach($cca_fees as $key => $value):?>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;"><?=$value->sef_fee_name;?></td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
				<td style="padding:4px; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
			</tr>
			<?endforeach;?>
			<?endif?>
			<?if(!empty($misc_fees)):?>
			<?foreach($misc_fees as $key => $value):?>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;"><?=$value->sef_fee_name;?></td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
				<td style="padding:4px; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
			</tr>
			<?endforeach;?>
			<?endif;?>
			<?if(!empty($other_fees)):?>
			<?foreach($other_fees as $key => $value):?>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;"><?=$value->sef_fee_name;?></td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
			<td style="padding:4px; text-align:right;"><?=money(round(floatval($value->sef_fee_rate),2));?></td>
			</tr>
			<?endforeach;?>
			<?endif;?>
			<?if(!empty($student_scholarships)):?>
			<? foreach($student_scholarships as $sc): ?>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;"><?=$sc->scholarship_name;?></td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; text-align:right;">- <?=money($sc->total_value_deducted);?></td>
				<td style="padding:4px; text-align:right;">- <?=money(round(floatval($sc->total_value_deducted),2));?></td>
			</tr>
			<? endforeach;?>
			<?endif;?>
			<?if(!empty($student_deduction)):?>
			<? foreach($student_deduction as $sd): ?>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;"><?=$sd->sdr_remarks;?></td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; text-align:right;">- <?=money($sd->sdr_amount);?></td>
				<td style="padding:4px; text-align:right;">- <?=money(round(floatval($sd->sdr_amount),2));?></td>
			</tr>
			<? endforeach;?>
			<?endif;?>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; font-weight:bold;">Sub Total</td>
				<td style="padding:4px; text-align:right;">PhP <strong><?php echo money(round($sum_amount_due + @$electives_total,2));?></strong></td>
			</tr>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; font-weight:bold;">Total Amount Paid</td>
				<td style="padding:4px; text-align:right;">- PhP <strong><?php echo money(round($sum_paid_fees,2));?></strong></td>
			</tr>
			<tr>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid;">&nbsp;</td>
				<td style="padding:4px; border-right:#000 1px solid; font-weight:bold;">Total Amount Due</td>
				<td style="padding:4px; text-align:right;">PhP <strong><?php echo money(round(($sum_amount_due + @$electives_total) - $sum_paid_fees,2));?></strong></td>
			</tr>			
		</table>
	</td><td>&nbsp;</td></tr>
</table>